<template>
  <div class="demo-inner-divider">基本用法</div>
  <ul v-infinite-scroll="load" class="infinite-list" style="overflow: auto">
    <li v-for="i in count" :key="i" class="infinite-list-item">{{ i }}</li>
  </ul>

  <div class="demo-inner-divider">Disable Loading</div>
  <div class="infinite-list-wrapper" style="overflow: auto">
    <ul
      v-infinite-scroll="load2"
      class="list"
      :infinite-scroll-disabled="disabled"
      :infinite-scroll-immediate="true"
      :infinite-scroll-delay="100"
    >
      <li v-for="i in count2" :key="i" class="list-item">{{ i }}</li>
    </ul>
    <p v-if="loading">Loading...</p>
    <p v-if="noMore">No more</p>
  </div>

  <infiniteScrollMd class="markdown-body" />
</template>

<script setup>
import { ref,computed } from 'vue'
import infiniteScrollMd from "../../docs/infiniteScroll.md"
const count = ref(0)
const load = () => {
  count.value += 2
}

const count2 = ref(10)
const loading = ref(false)
const noMore = computed(() => count2.value >= 20)
const disabled = computed(() => loading.value || noMore.value)
const load2 = () => {
  loading.value = true
  setTimeout(() => {
    count2.value += 2
    loading.value = false
  }, 2000)
}
</script>

<style>
.infinite-list {
  height: 300px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.infinite-list .infinite-list-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background: #ecf5ff;
  margin: 10px;
  color: #409eff;
}
.infinite-list .infinite-list-item + .list-item {
  margin-top: 10px;
}


.infinite-list-wrapper {
  height: 300px;
  text-align: center;
}
.infinite-list-wrapper .list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.infinite-list-wrapper .list-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background: #fef0f0;
  color: #f56c6c;
}
.infinite-list-wrapper .list-item + .list-item {
  margin-top: 10px;
}
</style>